package com.example.demo.service.Impl;
import com.example.demo.bean.BaseRolePrivilege;
import com.example.demo.bean.BaseRolePrivilegeExample;
import com.example.demo.dao.BaseRolePrivilegeMapper;
import com.example.demo.service.IBaseRolePrivilegeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseRolePrivilegeServiceImpl implements IBaseRolePrivilegeService {

    @Resource
    private BaseRolePrivilegeMapper baseRolePrivilegeMapper;

    @Override
    public List<BaseRolePrivilege> query(Long roleId) {
        BaseRolePrivilegeExample example=new BaseRolePrivilegeExample();
        if (!StringUtils.isEmpty(roleId)) {
            example.createCriteria().andRoleIdEqualTo(roleId);
        }
        return baseRolePrivilegeMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(BaseRolePrivilege baseRolePrivilege){
        if(baseRolePrivilege.getRoleId()==null){
            baseRolePrivilegeMapper.insert(baseRolePrivilege);
        }else{
            baseRolePrivilegeMapper.updateByPrimaryKey(baseRolePrivilege);
        }
    }


    @Override
    public void deleteById(long roleId){
        baseRolePrivilegeMapper.deleteByPrimaryKey(roleId);
    }
}
